package Person_JavaBean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JdbcUtil {
    public static Connection getConnection(){
        Connection conn = null;
        PreparedStatement pstmt = null;
        String driverName = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "root";
        String dbName = "bloody_characters_db";
        String url = "jdbc:mysql://localhost:3306/bloody_characters_db?characterEncoding=GBK";
        try{
            Class.forName(driverName);
            conn = DriverManager.getConnection(url,userName,password);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            return conn;
        }
    }
    public static void free(ResultSet rs,PreparedStatement ps,Connection conn){
        try {
            if (rs != null){
                rs.close();
            }
            if (ps != null){
                ps.close();
            }
            if (conn != null){
                conn.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
